package com.zmn.oms.admin.controller.callpop;

import com.zmn.common.dto.LayuiTableResponseDTO;
import com.zmn.common.utils.date.DateUtil;
import com.zmn.oms.business.interfaces.callpop.CallRecordBService;
import com.zmn.oms.common.dto.ResultDTO;
import com.zmn.oms.model.vo.call.CallRecordVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;
import java.util.List;

/**
 * 类描述：呼叫通话记录
 *
 * @author lujia
 * @date 2019/02/18 17:28
 */
@Controller
@RequestMapping("/call/record")
public class CallRecordController {

    private static final Logger logger = LoggerFactory.getLogger(CallRecordController.class);

    @Autowired
    CallRecordBService callRecordBService;

    /**
     * 通话记录
     * @param phone
     * @param mv
     * @return
     */
//    @RequiresPermissions("/zs/call/record/list.action")
    @RequestMapping("/list")
    public ModelAndView list(@RequestParam(required = false) String phone, ModelAndView mv) {
        logger.debug("#call#record params : {}", phone);
        mv.addObject("phone", phone);
        mv.setViewName("call/record/list");
        return mv;
    }

    /**
     * 通话记录
     * @param phone
     * @return
     */
//    @RequiresPermissions("/zs/call/record/list.action")
    @RequestMapping("/ajax/list")
    @ResponseBody
    public ResultDTO ajaxRecord(@RequestParam String phone) {
        logger.debug("#call#record params : {}", phone);
        // 用户查询六个自然月的通话记录
        Date endDate = DateUtil.getNow();
        Date startDate = DateUtil.addDays(endDate, -180);
        List<CallRecordVO> recordList = callRecordBService.listCallRecordByPhone(phone, startDate, endDate);
        LayuiTableResponseDTO data = LayuiTableResponseDTO.success(recordList.size(), recordList);
        return ResultDTO.success(data);
    }
}